<template>
  <div class="list">
    <el-table :data="tableData" class="main" max-height="250">
      <el-table-column type="index" width="120"> </el-table-column>
      <el-table-column prop="jrid" label="等级"> </el-table-column>
      <el-table-column prop="levelname" label="等级名称"> </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.row)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { levelList, deleteLevel } from "@/api/level";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.init();
  },
  updated() {
    // this.init();
  },
  methods: {
    init() {
      levelList()
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.records;
          }
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //有顺序的
    deleteRow(rows) {
      console.log(rows);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteLevel([rows.jrid])
            .then((res) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.init();
            })
            .catch((err) => {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
<style scoped>
.main {
  width: 50%;
  margin: 100px auto;
}
</style>